namespace CaltechSoft.Service.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class WorkOrder : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.WorkOrders",
                c => new
                    {
                        WorkOrderId = c.Int(nullable: false, identity: true),
                        WorkOrderNo = c.String(),
                        CustomerId = c.Int(nullable: false),
                        EquipmentId = c.Int(nullable: false),
                        CalibrationCycle = c.String(),
                        CalibrationDate = c.DateTime(nullable: false),
                        NextDueDate = c.DateTime(nullable: false),
                        PONumber = c.String(),
                        SalesmanId = c.String(maxLength: 128),
                        CreatedBy = c.Int(nullable: false),
                        CreatedDate = c.DateTime(),
                        UpdatedDate = c.DateTime(),
                        UpdatedBy = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.WorkOrderId)
                .ForeignKey("dbo.Customers", t => t.CustomerId, cascadeDelete: true)
                .ForeignKey("dbo.AspNetUsers", t => t.SalesmanId)
                .Index(t => t.CustomerId)
                .Index(t => t.SalesmanId);
            
            AddColumn("dbo.Equipment", "WorkOrder_WorkOrderId", c => c.Int());
            CreateIndex("dbo.Equipment", "WorkOrder_WorkOrderId");
            AddForeignKey("dbo.Equipment", "WorkOrder_WorkOrderId", "dbo.WorkOrders", "WorkOrderId");
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.WorkOrders", "SalesmanId", "dbo.AspNetUsers");
            DropForeignKey("dbo.Equipment", "WorkOrder_WorkOrderId", "dbo.WorkOrders");
            DropForeignKey("dbo.WorkOrders", "CustomerId", "dbo.Customers");
            DropIndex("dbo.WorkOrders", new[] { "SalesmanId" });
            DropIndex("dbo.WorkOrders", new[] { "CustomerId" });
            DropIndex("dbo.Equipment", new[] { "WorkOrder_WorkOrderId" });
            DropColumn("dbo.Equipment", "WorkOrder_WorkOrderId");
            DropTable("dbo.WorkOrders");
        }
    }
}
